package com.hbzhit.common.aspect;

import com.hbzhit.common.exception.RRException;
import com.hbzhit.config.RedisProperties;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.context.annotation.Configuration;

/**
 * Redis切面处理类
 *
 * @author Mark sunlightcs@gmail.com
 */
@Aspect
@Slf4j
@Configuration
@AllArgsConstructor
public class RedisAspect {

    private final RedisProperties redisProperties;

    @Around("execution(* com.hbzhit.common.utils.RedisUtils.*(..))")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        Object result = null;
        if(redisProperties.isOpen()){
            try{
                result = point.proceed();
            }catch (Exception e){
                log.error("redis error", e);
                throw new RRException("Redis服务异常");
            }
        }
        return result;
    }
}
